PageInfo.register({"type": "plug","info": function(require) {
		
	 
		var FunUtil = {};

		FunUtil.common4init = function() {

			String.HasText = function(str) {
				try {

					if(typeof(str) == "undefined") return false;
					if(str == null) return false;
					if(str == 'null') return false;
					if(str == 'undefined') return false;

					if(typeof(str) == 'string')
						str = str.replace(/(^\s*)|(\s*$)/g, '');
					if(str === '') return false;

				} catch(e) {
					return false;
				}
				return true;
			};
		};
		
		FunUtil.validate = function(value) {
            var result = true;
            
            var pattern = /[`~!@#$%^&*()_+<>?:"{}]/im;
		       // if (value === '' || value === null) result= false;
		    if (pattern.test(value)) {
		       // alert("非法字符！");
		    	result = false;
		    }
		    
		    return result;
		}


		FunUtil.request = function(data) {
			FunUtil.common4init();
			var execuFun = {};

			execuFun.pub = function() {
				
				
				//封装表单 check
				 

				/*原理类似只需在options 添加参数进行判断 */
				if(!String.HasText(data.method)) return;

				if(data.method == "post")	{
					var sparam = Object.assign({},data.param);
					var filter = ["positionDesc","positionRequirements","companyBenefit","companySynopsis" ];
				    filter.forEach(function(key){
				    	try{ delete sparam[key]; }catch(e){ }
				    });
					sparam = JSON.stringify(sparam);
					
                    var str =sparam.replace(/<[^>]+>/g,"");
					
					 if((str) != (sparam) ){
						 
						 layer.msg("有非法字符 修改后输入");
						 setTimeout(function(){ layer.close(); },3000)
						 
						 return;
					 }
					 
					 data.param = JSON.stringify(data.param);
				}


				//登录过滤
                var token = localStorage.getItem("auth");

                if(data.url.indexOf(".js") > 0 || data.url.indexOf("login") > 0){


                }else{
                    if(!String.HasText(token)) {
                        PageInfo.FunUtil.common4openUrl({"url":"login-index"})
                    };

                }
				
				var index = "";
				try{
					index =layer.load();
				}catch(e){
					//TODO handle the exception
				}
				
				
			

    
				$.ajax({
					type: data.method,
					url: data.url,
					data: data.param,
				/*	dataType: "json",*/
					contentType: "application/json",
                    beforeSend:function(xhr){
						console.log(xhr)
						if(String.HasText(token)) xhr.setRequestHeader("access_token",token);
					},
					success: function(cdata, status, xhr) {
						try{ layer.close(index);  }catch(e){ }
						var isdiss = ("code" in cdata) && (cdata.code == "9004");
						var isSuc  = ("code" in cdata) && (cdata.code == "200");
						
						
						
						if(isdiss){
							 PageInfo.FunUtil.common4openUrl({"url":"login/index"});
							 
							 return;
						}
						
						if(!isSuc){
							if(typeof cdata.message == "string"){
								
								layer.msg(cdata.message);
							}else{
								var result = "";
								for(var p in cdata.message){
									result = cdata.message[p];
									
									break;
								}
								layer.msg(result);
								
								
							}
							
						   return;
						}

						data.success(cdata,xhr);
					},
					error: function(data) {
						try{ layer.close(index);  }catch(e){ }

					}
				});

			};

			/* 
			 *  ==== 必填
			 * method: 执行方法 get post delete put
			 * url: 参数地址
			 * success:成功回调
			 * param: 传递参数
			 * 
			 *  ==== 可填可不填
			 * fail:失败回调
			 * async: 默认 true
			 * 
			 *FunUtil.request({"url","method":"put","param":{},"success":function(){
			 *}})
			 * 
			 * */
			execuFun.pub();

		};

		/*请求集合 */

		FunUtil.post = function(url,param, callback) {
		   FunUtil.request({ "method": "post", "url": url, "param": param, "success": callback });
		};

		FunUtil.get = function(url,param, callback) {

		   FunUtil.request({ "method": "get", "url": url, "param": param, "success": callback });

		};
 
		
		
		return FunUtil;
}});